package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsAdminMapper;
import com.qf.mapper.DtsRoleMapper;
import com.qf.pojo.DtsAdmin;
import com.qf.pojo.DtsRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class DtsRoleServiceImpl implements DtsRoleService{
    @Autowired
    private DtsRoleMapper roleMapper;
    @Autowired
    private DtsAdminMapper adminMapper;

    /**
     * 根据角色id数组返回对应的角色名称集合
     * @param roleIds
     * @return
     */
    @Override
    public Set<String> queryByIds(Integer[] roleIds) {
        Set<String> roles = new HashSet<String>();
        if (roleIds == null || roleIds.length == 0) {
            return roles;
        }

        //设置查询条件
        QueryWrapper<DtsRole> wapper = new QueryWrapper<>();
        wapper.in("id", Arrays.asList(roleIds));
        wapper.eq("deleted", false);
        wapper.eq("enabled", true);

        //查询
        List<DtsRole> roleList = roleMapper.selectList(wapper);

        for (DtsRole role : roleList) {
            roles.add(role.getName());
        }

        return roles;
    }

    /**
     * 查询所有的角色
     * @return
     */
    @Override
    public List<Map<String,Object>> options() {
        QueryWrapper<DtsRole> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id value ,name label").eq("deleted",false);//启用
        return roleMapper.selectMaps(queryWrapper);

    }

    @Override
    public List<Map<String, Object>> options1() {
        QueryWrapper<DtsAdmin> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id value ,username label").eq("deleted",false);//启用
        return adminMapper.selectMaps(queryWrapper);

    }

}
